﻿using MyOS.Models;

namespace MyOS
{
    public class ReadyQueue
    {
        static ReadyQueue()
        {
            PcbStart = null;
            PcbEnd = null;
        }

        public static PCBModel PcbStart { set; get; }
        public static PCBModel PcbEnd { set; get; }


        public static void Add(PCBModel pcb)
        {
            pcb.State = emState.ready;
            if (PcbEnd == null && PcbStart == null)
            {
                PcbStart = pcb;
                PcbEnd = pcb;
            }
            else
            {
                PcbEnd.Next = pcb;
                PcbEnd = pcb;
            }

            PcbEnd.Next = null;
        }

        public static PCBModel Get()
        {
            if (PcbEnd == null && PcbStart == null)
            {
                return null;
            }

            var pcbTemp = PcbStart;
            PcbStart = PcbStart.Next;
            if (PcbStart == null) PcbEnd = null;
            return pcbTemp;
        }
    }
}